package com.jason.platform.supervision.task;

import android.util.Log;
import com.google.gson.GsonBuilder;
import com.jason.platform.supervision.beans.LocateResp;
import com.jason.platform.supervision.beans.NotifyResp;
import org.kymjs.aframe.http.HttpCallBack;
import org.kymjs.aframe.utils.CodecUtils;

/**
 * @ClassName: QueryAllRecordTask
 * @Description: 查询所有电子档案
 * @Author: Jason.Zhang zhangyujn1989ok@gmail.com
 * @Date: 2015-8-12 05:39:48
 */
public class QueryLocateListTask extends Task {

    private static final String TAG = QueryLocateListTask.class.getSimpleName();

    public QueryLocateListTask(TaskListener listener){
        super(listener);
    }


    @Override
    public void execute() {
        Log.i(TAG, "post Params:" + mParams.getParamString());
        mKJHttp.post(HttpConfig.URL_API_HOST + HttpConfig.POST_URL_LOCATE_GETLOCATELIST, mParams, new HttpCallBack() {
            @Override
            public void onLoading(long count, long current) {

            }

            @Override
            public void onSuccess(Object arg0) {
                String result = null;
                try {
                    result = CodecUtils.base64Decode(arg0.toString());
                    Log.i(TAG,"post Result:" +  result);
                    LocateResp baseBean = new GsonBuilder().create().fromJson(
                            result, LocateResp.class);
                    if (baseBean != null){
                        if (baseBean.getValues() != null &&  !baseBean.getValues().isEmpty()){
                            isSuccess = true;
                            resData = baseBean;
                        }else{
                            isSuccess = false;
                            rspDesc = baseBean.getRespMsg();
                        }
                    }else {
                        isSuccess = false;
                        rspDesc = "连接失败，请重试";
                    }
                }catch (Exception e){
                    isSuccess = false;
                    rspDesc = "连接失败，请重试";
                }

                listener.onTaskResult(QueryLocateListTask.this);
            }

            @Override
            public void onFailure(Throwable t, int errorNo, String strMsg) {
                Log.i(TAG, "stateCode:"+ errorNo + ",errorMessage" + strMsg);
                isSuccess = false;
                rspDesc = "连接失败，请重试";
                listener.onTaskResult(QueryLocateListTask.this);
            }
        });

    }
}
